<?php
namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class CommonController extends Controller
{

    const LimitMinValue = 10;
    const LimitMaxValue = 100;

    /**
     * @var Request
     */
    protected $request;
    /**
     * @var mixed
     */
    protected $limit;

    /**
     * 构造函数
     * CommonController constructor.
     * @param Request $request
     */
    public function __construct(Request $request)
    {
        $this->request    = $request;
        $this->limit      = $request->get('limit') ?? self::LimitMinValue;
    }

    /**
     * 接收请求参数
     * @param string|null $paramKey
     * @return array|mixed
     * @name:input
     * @author: lisa
     * @datetime: 2021/10/12 10:09
     */
    public function input(string $paramKey = null)
    {
        if (!$paramKey) return $this->request->all();
        return $this->request->get($paramKey);
    }

    /**
     * 记录日志
     * @param $str
     * @name:addLog
     * @author: lisa
     * @datetime: 2021/10/12 10:08
     */
    public function addLog($str)
    {
        Log::info("用户端-" . $str);
    }

    public static $attr = [
        'pass_word'           => '密码',
        'mobile'              => '手机号',
        'verify_code'         => '验证码',
        'old_pwd'             => '旧密码',
        'new_pwd'             => '新密码',
        're_pass_word'        => '再次密码',
        'page'                => '页数',
        'limit'               => '条数',
        'lng'                 => '经度',
        'lat'                 => '纬度',
        'address_id'          => '地址ID',
        'order_id'            => '运单ID',
        'trade_type'          => '支付类型',
        'score'               => '评分',
        'amount'              => '金额',
        'list_type'           => '列表类型',
        'grade'               => '会员等级',
        'cover_url'           => '封面地址',
        'content'             => '内容',
        'reason'              => '原因',
        'real_name'           => '姓名',
        'id_card_no'          => '身份证号',
        'sex'                 => '性别',
        'age'                 => '年龄',
        'province_id'         => '省份ID',
        'city_id'             => '城市ID',
        'district_id'         => '区县ID',
        'id_card_front_image' => '身份证正面照',
        'id_card_back_image'  => '身份证反面照',
        'address_no'          => '地址编码',
        'special_id'          => '专业ID',
        'cat_id'              => '栏目ID',
        'article_no'          => '文章编号',
        'type'                => '类型',
    ];

    public static $rules = [
        'page'       => 'nullable|integer|min:1',
        'limit'      => 'nullable|integer|min:1',
    ];
}
